<?php include('scripts.php'); ?>

<script type="text/javascript" language="javascript">
$(function() {
    $("#cbo_ecashAmount").change(function(){
        var ecashFinal = parseFloat($("#cbo_ecashAmount").val()) * 1.1;
        /*var ecashFinal = $("#cbo_ecashAmount").val();*/

        $("#ecashFinal").autoNumericSet(ecashFinal);
    }).change();

    $("#withdrawForm").validate({
        messages : {
            transactionPassword: {
                remote: "Security Password is not valid."
            }
        },
        rules : {
            "transactionPassword" : {
                required : true
                , remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            waiting();
                var ecashBalance = $('#ecashBalance').autoNumericGet();
                var withdrawAmount = parseFloat($("#cbo_ecashAmount").val())  * 1.1;

                if (withdrawAmount > parseFloat(ecashBalance)) {
                    alert("In-sufficient e-Cash");
                    return false;
                }

                form.submit();
        }
    });
});
</script>

<form action="/member/ecashWithdrawal" id="withdrawForm" name="withdrawForm" method="post">
    <div style="padding: 10px; top: 30px; width: 98%">
        <div class="portlet">
            <div class="portlet-header"><?php echo __('e-Cash Withdrawal') ?></div>
            <div class="portlet-content">

                <table cellpadding="0" cellspacing="5" align="center" border="0">
                    <tr>
                        <td colspan=2 align='center'>
                        <?php if ($sf_flash->has('successMsg')): ?>
                            <div class="ui-widget">
                                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-highlight ui-corner-all">
                                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>
                                    <strong><?php echo $sf_flash->get('successMsg') ?></strong></p>
                                </div>
                            </div>
                        <?php endif; ?>
                        <?php if ($sf_flash->has('errorMsg')): ?>
                            <div class="ui-widget">
                                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-error ui-corner-all">
                                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
                                    <strong><?php echo $sf_flash->get('errorMsg') ?></strong></p>
                                </div>
                            </div>
                        <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('e-Cash Balance'); ?></strong>
                        </td>
                        <td>
                            <input name="ecashBalance" id="ecashBalance" tabindex="1" disabled="disabled"
                                   value="<?php echo number_format($ledgerAccountBalance, 2); ?>"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('e-Cash Withdrawal Amount'); ?></strong>
                        </td>
                        <td>
                            <select name="ecashAmount" id="cbo_ecashAmount" tabindex="2">
                                <option value="200">200</option>
                                <option value="500">500</option>
                                <option value="1000">1,000</option>
                                <option value="1500">1,500</option>
                                <option value="2000">2,000</option>
                                <option value="2500">2,500</option>
                                <option value="3000">3,000</option>
                                <option value="3500">3,500</option>
                                <option value="4000">4,000</option>
                                <option value="4500">4,500</option>
                                <option value="5000">5,000</option>
                                <?php
                                    for ($i = 6000; $i <= 100000; $i = $i + 1000) {
                                        echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                                    }

                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr class="tbl_form_row_odd">

                        <td>
                            <?php echo __('After 10% handling fee'); ?>
                        </td>
                        <td>
                            <input name="ecashFinal" type="text" id="ecashFinal" readonly="readonly"/>
                        </td>

                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('Security Password'); ?></strong>
                        </td>
                        <td>
                            <input name="transactionPassword" type="password" id="transactionPassword" tabindex="3"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan='2' align="center">
                            <!--<font color="#dc143c"> <?php /*echo __('Note : charge 5% handling fees when CP2 withdrawal requested. ') */?></font>-->
                            <font color="#dc143c"><?php echo __('NOTE : Minimum withdrawal amount : USD 200') ?><br>
                            <?php echo __('Can only be withdrawn on the first working week of the month') ?><br>
                            <?php echo __('Processing time : 7 working days') ?></font>
                        </td>
                    </tr>
                    <tr>
                        <td colspan=2 align='center'>
                            <button id="btnTransfer"><?php echo __('Submit') ?></button>
                        </td>
                    </tr>
                </table>

                <script type="text/javascript" language="javascript">
                    var datagrid = null;
                    $(function() {
                        datagrid = $("#datagrid").r9jasonDataTable({
                            // online1DataTable extra params
                            "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
                            "extraParam" : function(aoData) { // pass extra params to server
                            },
                            "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
                                reassignDatagridEventAttr();
                            },

                            // datatables params
                            "bLengthChange": true,
                            "bFilter": false,
                            "bProcessing": true,
                            "bServerSide": true,
                            "bAutoWidth": false,
                            "sAjaxSource": "/finance/ecashWithdrawalList",
                            "sPaginationType": "full_numbers",
                            "aaSorting": [
                                [5,'desc']
                            ],
                            "aoColumns": [
                                { "sName" : "dist_id", "bVisible" : false,  "bSortable": true},
                                { "sName" : "created_on",  "bSortable": true},
                                { "sName" : "amount",  "bSortable": true},
                                { "sName" : "deduct",  "bSortable": true},
                                { "sName" : "status_code",  "bSortable": true},
                                { "sName" : "remarks",  "bSortable": true}
                                    ]
                                });
                    }); // end function

                    function reassignDatagridEventAttr() {
                    }
                </script>

                <div class="portlet">
                    <div class="portlet-header"><?php echo __('e-Cash Withdrawal Status') ?></div>
                    <div class="portlet-content">

                        <table class="display" id="datagrid" border="0" width="100%">
                            <thead>
                            <tr>
                                <th></th>
                                <th><?php echo __('Date') ?></th>
                                <th><?php echo __('Withdrawal') ?></th>
                                <th><?php echo __('Deduct Amount') ?></th>
                                <th><?php echo __('Status') ?></th>
                                <th><?php echo __('Remarks') ?></th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>